<%@page import="classes.Valuta"%>
<%@include file="template/configuration.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>${website} || Payment</title>
        ${stylesheet}
        ${jquery}
        ${jsdropdown}
    </head>
    <body>
        <c:set var="selmet" value=""></c:set>
            <div class="container">
            <%@include file="template/header.jsp" %>
            <div class="content">
                <c:choose>
                    <c:when test="${sessionScope.userrole == 'Administrator'}">                                                                     
                        <h1>Manage payment methods</h1>
                        <div class="third-block no-height">
                            <a href="Payment?add">Add a new payment method <img src="${url}images/add.png" border="0" class="icon-text"></a>
                        </div>
                        <div class="clear margin-bottom-10"></div>
                        <div class="full-block">
                            <c:choose>
                                <c:when test="${methods != null}">
                                    <table class="overview">                                    
                                        <tr>
                                            <th>Name</th>
                                            <th>Redirect</th>
                                            <th class="manage">Manage</th>
                                        </tr>
                                        <c:set var="i" value="0"/>
                                        <c:forEach items="${methods}" var="methods">
                                            <c:set var="i" value="${i + 1}"/>    
                                            <tr class="<c:choose><c:when test="${i % 2 == 0}">even</c:when><c:otherwise>odd</c:otherwise></c:choose>">
                                                <td>${methods.name}</td>
                                                <td>${methods.link}</td>
                                                <td>
                                                    <a href="${url}Payment?id=${methods.id}"><img src="${url}images/edit.png" /></a> 
                                                    <a href="${url}Payment?idremove=${methods.id}" class="remove"><img src="${url}images/remove.png" /></a>                                    
                                                    <span class="info">method</br> <strong>${methods.name} </strong></span>
                                                </td>
                                            </tr>    
                                        </c:forEach>                                
                                    </table>
                                </c:when>
                                <c:otherwise>
                                    <div class="no-yet-message">
                                        There are no payment methods at this moment yet.
                                    </div>
                                </c:otherwise>
                            </c:choose>
                        </div>
                    </c:when>    
                    <c:otherwise>
                        <h1>Payment</h1>
                        <div class="steps-block">
                            <h1>Step</h1>
                            <div class="steps">
                                <div class="step <c:if test='${step == 1}'>active</c:if> border-rounded-left">
                                    1
                                </div>
                                <div class="separator">
                                    &nbsp;
                                </div>
                                <c:if test="${step == 1}">
                                    <div class="information">
                                        Verify course
                                    </div>
                                </c:if>
                                <div class="step <c:if test='${step == 2}'>active</c:if>">
                                    2
                                </div>
                                <div class="separator">
                                    &nbsp;
                                </div>
                                <c:if test="${step == 2}">
                                    <div class="information">
                                        Choose payment
                                    </div>
                                </c:if>
                                <div class="step <c:if test='${step == 3}'>active</c:if> <c:if test='${step != 3}'>border-rounded-right strange-padding</c:if>">
                                    3
                                </div>
                                <c:if test="${step == 3}">
                                    <div class="separator">
                                        &nbsp;
                                    </div>
                                    <div class="information border-rounded-right">
                                        Finish payment
                                    </div>
                                </c:if>
                            </div>
                        </div>
                        <c:if test="${step == 3}">                                               
                            <form action="Payment" method="POST">
                            </c:if>
                            <fieldset class="payment-block">
                                <legend align="center">
                                    <c:if test="${step == 1}">
                                        <div class="button no-link"><a>Select courses</a></div>
                                    </c:if>
                                    <c:if test="${step == 2}">    
                                        <div class="button no-link"><a>Select method</a></div>
                                    </c:if>
                                    <c:if test="${step == 3}">                               
                                        <div class="button no-link"><a>Complete payment</a></div>
                                    </c:if>    
                                </legend>
                                <table class="payment-table">
                                    <tr>
                                        <td>
                                            <img src="${url}images/logo-watermark.png">
                                        </td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${step == 2}">
                                                    <c:set var="selmet" value="${selected}"></c:set>
                                                    <h4>Payment method</h4>
                                                    <form action="Payment" method="POST">
                                                        <input type="hidden" value="methodselect" name="formoption"/> 
                                                        <div class="relative">
                                                            <select class="select" name="methodoption" onchange="this.form.submit()">
                                                                <option value="0">Choose payment method</option>
                                                                <c:forEach items="${methods}" var="methods">
                                                                    <option value="${methods.id}" <c:if test="${selected == methods.id}">selected="selected"</c:if>>${methods.name}</option>
                                                                </c:forEach>
                                                            </select>
                                                            <span class="pointer"><span>
                                                        </div>
                                                    </form>
                                                </c:when>
                                                <c:when test="${step == 3}">
                                                    <input type="hidden" value="finishpayment" name="formoption"/> 
                                                    <div class="payment-tab">
                                                        <table>                                    
                                                            <tr>
                                                                <c:choose>
                                                                    <c:when test="${fn:length(sessionScope.cart.cart) == 0}">
                                                                        <th colspan="3" style="height: 30px; font-weight: normal; padding-left: 15px;">Add first a course to your cart.</th>
                                                                    </c:when>
                                                                    <c:otherwise>
                                                                        <th></th>
                                                                        <th class="name">Name</td>
                                                                        <th>Price</td>
                                                                    </c:otherwise>
                                                                </c:choose>
                                                            </tr>
                                                            <c:forEach items="${sessionScope.cart.cart}" var="cart">
                                                                <tr>
                                                                    <td></td>
                                                                    <td>${cart.name}</td>
                                                                    <td>
                                                                        <c:set var="price" value="${cart.price}" />
                                                                        <%=Valuta.getSignFromCurrency(pageContext.getAttribute("currency").toString())%> 
                                                                        <%=Valuta.calculateToCurrency(pageContext.getAttribute("currency").toString(), (Double) Double.parseDouble(pageContext.getAttribute("price").toString()))%>
                                                                    </td>                                
                                                                </tr>                                    
                                                            </c:forEach> 
                                                            <tr class="total">
                                                                <td></td>
                                                                <td>Total price</td>
                                                                <td>
                                                                    <c:choose>
                                                                        <c:when test="${cartx != null}">
                                                                            <c:set var="price" value="${cartx}" />
                                                                            <%=Valuta.getSignFromCurrency(pageContext.getAttribute("currency").toString())%> 
                                                                            <%=Valuta.calculateToCurrency(pageContext.getAttribute("currency").toString(), (Double) Double.parseDouble(pageContext.getAttribute("price").toString()))%>
                                                                        </c:when>
                                                                        <c:otherwise>
                                                                            <%=Valuta.getSignFromCurrency(pageContext.getAttribute("currency").toString())%>
                                                                            <%=Valuta.calculateToCurrency(pageContext.getAttribute("currency").toString(), (Double) Double.parseDouble("0.00"))%>
                                                                        </c:otherwise>
                                                                    </c:choose>
                                                                </td>
                                                            </tr>                                                                            
                                                        </table>                           
                                                    </div>
                                                    <div class="payment-tab">
                                                        <table>
                                                            <tr style="height: 30px;">
                                                                <td></td>
                                                                <td style="color: #1a344b;">Amount</td>
                                                                <td>${carta}</td>
                                                            </tr>
                                                            <tr valign="bottom">
                                                                <td></td>
                                                                <td colspan="2" style="color: #1a344b;">Payment method</td>
                                                            </tr>
                                                            <tr>
                                                                <td></td>
                                                                <td colspan="2">${selectmethod.name}</td>
                                                            </tr>
                                                            <tr style="height: 30px;" valign="bottom">
                                                                <td></td>
                                                                <td colspan="2" style="color: #1a344b;">Creditcard number</td>
                                                            </tr>
                                                            <tr style="height: 30px;">
                                                                <td></td>
                                                                <td colspan="2"><input type="text" name="creditcardnumber"/></td>
                                                            </tr>
                                                            <tr style="height: 8px;">
                                                                <td colspan="3"></td>
                                                            </tr>
                                                        </table>
                                                    </div>
                                                </c:when>
                                                <c:otherwise>
                                                    <div class="payment-tab">
                                                        <table>                                    
                                                            <tr>
                                                                <c:choose>
                                                                    <c:when test="${fn:length(sessionScope.cart.cart) == 0 || fn:length(sessionScope.cart.cart) == 0}">
                                                                        <th colspan="3" style="font-weight: normal; padding-left: 15px; height: 30px;">Add a course to your cart first.</th>
                                                                    </c:when>
                                                                    <c:otherwise>
                                                                        <th></th>
                                                                        <th class="name">Name</td>
                                                                        <th>Price</td>
                                                                    </c:otherwise>
                                                                </c:choose>
                                                            </tr>
                                                            <c:forEach items="${sessionScope.cart.cart}" var="cart">
                                                                <tr>
                                                                    <td></td>
                                                                    <td>
                                                                        ${cart.name}
                                                                        <a href="CartController?courseid=${cart.id}&remove=0" class="float-right" style="margin-top: 3px; margin-right: 10px;">
                                                                            <img src="${url}images/cross.png" title="Remove" />
                                                                        </a>
                                                                    </td>
                                                                    <td>
                                                                        <c:set var="price" value="${cart.price}" />
                                                                        <%=Valuta.getSignFromCurrency(pageContext.getAttribute("currency").toString())%> 
                                                                        <%=Valuta.calculateToCurrency(pageContext.getAttribute("currency").toString(), (Double) Double.parseDouble(pageContext.getAttribute("price").toString()))%>
                                                                    </td>                                
                                                                </tr>                                    
                                                            </c:forEach> 
                                                            <tr class="total">
                                                                <td></td>
                                                                <td>Total price</td>
                                                                <td>
                                                                    <c:choose>
                                                                        <c:when test="${cartx != null}">
                                                                            <c:set var="price" value="${cartx}" />
                                                                            <%=Valuta.getSignFromCurrency(pageContext.getAttribute("currency").toString())%> 
                                                                            <%=Valuta.calculateToCurrency(pageContext.getAttribute("currency").toString(), (Double) Double.parseDouble(pageContext.getAttribute("price").toString()))%>
                                                                        </c:when>
                                                                        <c:otherwise>
                                                                            <%=Valuta.getSignFromCurrency(pageContext.getAttribute("currency").toString())%> 
                                                                            <%=Valuta.calculateToCurrency(pageContext.getAttribute("currency").toString(), (Double) Double.parseDouble("0.00"))%>
                                                                        </c:otherwise>
                                                                    </c:choose>
                                                                </td>
                                                            </tr>                                                                            
                                                        </table>                           
                                                    </div> 
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                        <td>
                                            <c:if test="${step == 1}">
                                                <div class="button">
                                                    <a href="${url}Category">Select more courses</a>
                                                </div>
                                            </c:if>
                                            <c:if test="${step == 3}">
                                                <div class="button">
                                                    <a href="${url}Payment?next=1">Edit courses</a>
                                                </div>
                                            </c:if>
                                        </td>
                                    </tr>
                                </table>                  
                            </fieldset>
                            <div class="step-buttons">
                                <c:choose>
                                    <c:when test="${step == 2}">
                                        <div class="button float-left">
                                            <a href="${url}Payment?next=1">&laquo; Step 1</a>
                                        </div>
                                        <div class="button float-right <c:if test="${selected == null}">disabled</c:if>">
                                            <a href="${url}Payment?next=3&select=${selmet}" <c:if test="${selected == null}">onclick="return false;"</c:if>>Step 3 &raquo;</a>
                                        </div>
                                    </c:when>
                                    <c:when test="${step == 3}">
                                        <div class="button float-left">
                                            <a href="${url}Payment?next=2">&laquo; Step 2</a>
                                        </div>
                                        <div class="button float-right">
                                            <input type="submit" value="Finish &raquo;"/>
                                        </div>
                                    </c:when>
                                    <c:otherwise>
                                        <div class="button float-right <c:if test='${cart == null || fn:length(cart.cart)==0}'>disabled</c:if>">
                                            <a href="${url}Payment?next=2" <c:if test="${cart == null || fn:length(cart.cart)==0}">onclick="return false;"</c:if>>Step 2 &raquo;</a>
                                        </div>
                                    </c:otherwise>
                                </c:choose>
                            </div>
                        </form>                    
                    </c:otherwise>
                </c:choose>                            
            </div>
            <%@include file="template/footer.jsp" %>
        </div>
    </body>
</html>
